<?

class MIXI
{


    private $refresh_token = 0;
    private $access_token = 0;

    public function authorize($authorization_code)
    {

        $url = 'https://secure.mixi-platform.com/2/token';
        $data = array(
            'grant_type' => 'authorization_code',
            'client_id' => 'b225fe62438fd46b986d',
            'client_secret' => 'b22cf64cfc03df7f0dc233e2cbaaf122691a509a',
            'code' => $authorization_code,
            'redirect_uri' => 'http://reafo.net/garden/call_back.php',
        );
        $options = array('http' => array(
            'method' => 'POST',
            'content' => http_build_query($data),
        ));

        $contents = file_get_contents($url, false, stream_context_create($options));
        
        if($http_response_header[0] == 'HTTP/1.1 200 OK')
        {
            $data = json_decode($contents);
            $this->set_refresh_token($data->refresh_token);
            $this->set_access_token($data->access_token);
            
            return true;
            //echo "OK";
        }
        else
        {
            return false;
            //echo "NG";
        }

    }


}

?>